package com.itheima.service.impl;

import com.itheima.dao.QrtzSimpropTriggersDao;
import com.itheima.pojo.QrtzSimpropTriggers;
import com.itheima.service.QrtzSimpropTriggersService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (QrtzSimpropTriggers)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:52
 */
@Service("qrtzSimpropTriggersService")
public class QrtzSimpropTriggersServiceImpl implements QrtzSimpropTriggersService {
    @Resource
    private QrtzSimpropTriggersDao qrtzSimpropTriggersDao;

    /**
     * 通过ID查询单条数据
     *
     * @param schedName 主键
     * @return 实例对象
     */
    @Override
    public QrtzSimpropTriggers queryById(String schedName) {
        return this.qrtzSimpropTriggersDao.queryById(schedName);
    }

    /**
     * 分页查询
     *
     * @param qrtzSimpropTriggers 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<QrtzSimpropTriggers> queryByPage(QrtzSimpropTriggers qrtzSimpropTriggers, PageRequest pageRequest) {
        long total = this.qrtzSimpropTriggersDao.count(qrtzSimpropTriggers);
        return new PageImpl<>(this.qrtzSimpropTriggersDao.queryAllByLimit(qrtzSimpropTriggers, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param qrtzSimpropTriggers 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzSimpropTriggers insert(QrtzSimpropTriggers qrtzSimpropTriggers) {
        this.qrtzSimpropTriggersDao.insert(qrtzSimpropTriggers);
        return qrtzSimpropTriggers;
    }

    /**
     * 修改数据
     *
     * @param qrtzSimpropTriggers 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzSimpropTriggers update(QrtzSimpropTriggers qrtzSimpropTriggers) {
        this.qrtzSimpropTriggersDao.update(qrtzSimpropTriggers);
        return this.queryById(qrtzSimpropTriggers.getSchedName());
    }

    /**
     * 通过主键删除数据
     *
     * @param schedName 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String schedName) {
        return this.qrtzSimpropTriggersDao.deleteById(schedName) > 0;
    }
}
